<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="/styles/bootstrap.css">
  <link rel="stylesheet" href="/styles/admin.css">
</head>

<body>
  <div class="login">
    <form class="login-wrap" id="form">
      <img class="avatar" src="/images/4.jpg">
      <!-- 有错误信息时展示 -->
      <div class="alert alert-danger hidden">
        <strong>错误！</strong><span></span>
      </div>
      <div class="form-group">
        <label for="name" class="sr-only">用户名</label>
        <input id="name" name="name" type="text" class="form-control" placeholder="用户名" value="" autofocus>
      </div>
      <div class="form-group">
        <label for="pass" class="sr-only">密码</label>
        <input id="pass" name="pass" type="password" class="form-control" value="" placeholder="密码">
      </div>
      <input id="btn" type="button" class="btn btn-primary btn-block" value="登 录">
    </form>
  </div>
  <script src="/libs/jquery.js"></script>
  <script>
    $('#btn').on('click', function () {
      $.ajax({
        type: 'post',
        url: 'http://127.0.0.1:3002/login',
        data: $('form').serialize(),
        dataType: 'json',
        success: function (res) {
          console.log(res)
          if (res.code == 200) {
            // 将后台返回的token数据存储到本地存储
            localStorage.setItem('mytoken_59', res.token)
            location.href = '/'
          } else {
            alert(res.msg)
          }
        }
      })
    })
  </script>
</body>

</html>